<?php
/**
 * @package Sj Content Slick Slider Responsive
 * @version 2.0
 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @copyright (c) 2013 YouTech Company. All Rights Reserved.
 * @author YouTech Company http://www.smartaddons.com
 *
 */
defined('_JEXEC') or die;

JHtml::script('modules/mod_sj_vm_slickslider_res/assets/js/jcarousel.js');
JHtml::stylesheet('templates/' . JFactory::getApplication()->getTemplate().'/html/mod_sj_vm_slickslider_res/slick-slider-res.css');
JHtml::stylesheet('modules/mod_sj_vm_slickslider_res/assets/css/slickslider-font-color.css');

//YTools::script('jcarousel.js');
//YTools::stylesheet('slick-slider-res.css');
//YTools::stylesheet('slickslider-font-color.css');

$image_config = array(
		'output_width'  => $params->get('big_item_image_width',  360),
		'output_height' => $params->get('big_item_image_height', 300),
		'function'		=> $params->get('big_item_image_function', 'resize_none'),
		'background'	=> $params->get('big_item_image_background', '#FFFFFF')
);
$vm_currency_display = &CurrencyDisplay::getInstance();

$start = (int)$params->get('start','');
if ($start < 1 || $start > count($list)){
	$start = 1;
}

$pause_hover = $params->get('pause_hover','1');
if ($pause_hover !='1'){
	$pause_hover = " ";
} else { $pause_hover = "hover"; }

//var_dump($pause_hover);die('abc');
$interval = (int)$params->get('interval','4000');
$effect = $params->get('effect','1');
if ($effect == '1') { $effect='slide';}
else $effect='';
$pag_position = $params->get('button_position' , 'conner-bl');
$pag_type = in_array($params->get('button_theme', 'num'), array('num', 'number')) ? 'type-num' : 'type-dot';
$slick_slider_background = $params->get('theme','theme1')=='theme1' ? 'bg-style1' : 'bg-style2';
?>

<?php if ($params->get('pretext') != ''){ ?>
<div class="text-block">
	<?php echo $params->get('pretext'); ?>
</div>
<?php }?>
<div id="sj-content-slickslider-res<?php echo $module->id?>" class="sj-content-slickslider-res <?php echo $effect ?>" data-pause="<?php echo $pause_hover;?>" data-start-jcarousel="1" data-interval="<?php echo $interval?>">
	<!-- Carousel items -->
	<div class="btn-pre" href="#sj-content-slickslider-res<?php echo $module->id?>" data-jslide="prev"></div>
	<div class="btn-next" href="#sj-content-slickslider-res<?php echo $module->id?>" data-jslide="next"></div>
    <div class="sj-slickslider-res-inner <?php echo $slick_slider_background?>">
    	<?php $i=1;
    	foreach ($list as $item){
			if ($i==$start){$active = 'active';}
    		else $active = '';
    		$i++;
    	?>
    	<div class="item clearfix <?php echo $active; ?> ">
			<div class="sj-slickslider-res-caption <?php if(empty($item->images)){ echo 'no-images'; } ?>">
				<div class="sj-slickslider-res-caption-inner">
					<?php if( (int)$params->get('show_title', 1) && $params->get('limit_title') !=0){ ?>
					<div class="item-title">
						<a href="<?php echo $item->link; ?>" <?php echo sj_vm_slicksliderres_helper::parseTarget($params->get('item_link_target'))?> >
							<?php echo YTools::truncate($item->product_name, $params->get('limit_title',25));?>
						</a>
					</div>
					<?php } 
					
					if( (int)$params->get('show_price', 1) ): ?>
						<div class="item-price">
							<div class="sale-price">
							<?php $currency = &CurrencyDisplay::getInstance();
							//var_dump($item->prices);
									if ( !empty($item->prices['salesPrice']) ){
										echo '<span class="saleprice">'.$currency->createPriceDiv('salesPrice', '', $item->prices, true).'</span>';
									}
									if ( !empty($item->prices['salesPriceWithDiscount']) ){
										echo '<span class="sale-with-discount">'.$currency->createPriceDiv('salesPriceWithDiscount', '', $item->prices, true).'</span>';
									}?>
							</div>
						</div>
					<?php endif;
					
					if( (int)$params->get('show_desc', 1) && $params->get('limit_desc') !=0 ){ ?>
					<div class="item-description">
						<?php $desc = "";
							if(!empty($item->product_s_desc)){
								YTools::extractImages($item->product_s_desc);
								$desc = $item->product_s_desc;	
							}else{
								YTools::extractImages($item->product_desc);
								$desc = $item->product_desc;	
							}
							if ( (int)$params->get('item_description_striptags', 1) ){
								$keep_tags = $params->get('item_description_keeptags', '');
								$keep_tags = str_replace(array(' '), array(''), $keep_tags);
								$tmp_desc = strip_tags($desc ,$keep_tags );
								echo YTools::truncate($tmp_desc, (int)$params->get('limit_desc'));
							} else {
								echo YTools::truncate($desc, (int)$params->get('limit_desc'));
							}?>
					</div>
					<?php }
					
					if( (int)$params->get('show_read_more', 1) ){ ?>
					<div class="item-readmore">
						<a href="<?php echo $item->link;?>"  <?php echo sj_vm_slicksliderres_helper::parseTarget($params->get('item_link_target'))?> >
							<?php echo $params->get('read_more_text', 'Read more'); ?>
						</a>
					</div>
					<?php } ?>
					
					
					
					<div class="addtocart-area">
						<form method="post" class="product js-recalculate" action="<?php echo JRoute::_ ('index.php'); ?>">
							<?php // Product custom_fields
							if (!empty($item->customfieldsCart)) {
								?>
								<div class="product-fields">
									<?php foreach ($item->customfieldsCart as $field) { ?>
									<div class="product-field product-field-type-<?php echo $field->field_type ?>">
										<span class="product-fields-title-wrapper"><span class="product-fields-title"><strong><?php echo JText::_ ($field->custom_title) ?></strong></span>
										<?php if ($field->custom_tip) {
										echo JHTML::tooltip ($field->custom_tip, JText::_ ($field->custom_title), 'tooltip.png');
									} ?></span>
										<span class="product-field-display"><?php echo $field->display ?></span>
					
										<span class="product-field-desc"><?php echo $field->custom_field_desc ?></span>
									</div><br/>
									<?php
								}
									?>
								</div>
								<?php
							}
							/* Product custom Childs
								 * to display a simple link use $field->virtuemart_product_id as link to child product_id
								 * custom_value is relation value to child
								 */
					
							if (!empty($item->customsChilds)) {
								?>
								<div class="product-fields">
									<?php foreach ($item->customsChilds as $field) { ?>
									<div class="product-field product-field-type-<?php echo $field->field->field_type ?>">
										<span class="product-fields-title"><strong><?php echo JText::_ ($field->field->custom_title) ?></strong></span>
										<span class="product-field-desc"><?php echo JText::_ ($field->field->custom_value) ?></span>
										<span class="product-field-display"><?php echo $field->display ?></span>
					
									</div><br/>
									<?php } ?>
								</div>
								<?php }
					
							if (!VmConfig::get('use_as_catalog', 0) and !empty($item->prices['salesPrice'])) {
							?>
					
							<div class="addtocart-bar">
					
								<?php // Display the quantity box
					
								$stockhandle = VmConfig::get ('stockhandle', 'none');
								if (($stockhandle == 'disableit' or $stockhandle == 'disableadd') and ($item->product_in_stock - $item->product_ordered) < 1) { ?>
									<a href="<?php echo JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&layout=notify&virtuemart_product_id=' . $item->virtuemart_product_id); ?>" class="notify"><?php echo JText::_ ('COM_VIRTUEMART_CART_NOTIFY') ?></a>
								<?php } else { ?>
									<?php
									// Display the add to cart button
									?>
									<span class="addtocart-button">
										<?php echo shopFunctionsF::getAddToCartButton ($item->orderable); ?>
									</span>
								
								<?php } ?>
					
								<div class="clear"></div>
							</div>
							<?php }
							 // Display the add to cart button END  ?>
							 
							<input type="hidden" name="quantity[]" value="<?php if (isset($item->min_order_level) && (int)$item->min_order_level > 0) {
											echo $item->min_order_level;
										} else {
											echo '1';
										} ?>"/>
							<input type="hidden" class="pname" value="<?php echo htmlentities($item->product_name, ENT_QUOTES, 'utf-8') ?>"/>
							<input type="hidden" name="option" value="com_virtuemart"/>
							<input type="hidden" name="view" value="cart"/>
							<noscript><input type="hidden" name="task" value="add"/></noscript>
							<input type="hidden" name="virtuemart_product_id[]" value="<?php echo $item->virtuemart_product_id ?>"/>
						</form>
					
						<div class="clear"></div>
					</div><!--end add to card-->
					
					
					
				</div>
			</div>
		
    		<?php if($item->images){?>
    		<div class="item-image">
				<img class="bg_slideshow" src="<?php echo JURI::base() . 'templates/' . JFactory::getApplication()->getTemplate().'/images/bg_slideshow.png';?>" alt="" />
    			<div class="item-image-inner">
					<a href="<?php echo $item->link; ?>" <?php echo sj_vm_slicksliderres_helper::parseTarget($params->get('item_link_target'))?>>
    					<img src="<?php echo Ytools::resize($item->images, $image_config);?>" alt="<?php echo $item->product_name; ?>" title="<?php echo $item->product_name; ?>" />	    				
					</a>
				</div>
			</div>
			<?php }?>
			
			
    	</div>
    	<?php } ?>
    </div>
    <!-- Carousel nav -->
	<div class="nav <?php echo $pag_position?>" >
		<ul class="<?php echo $pag_type;?>">
			<?php for($i=0; $i<count($list); $i++){
				if ($i+1==$start){$sel = 'sel';}
	    		else $sel = '';
			?>
			<li class="pag-item <?php echo $sel; ?>" href="#sj-content-slickslider-res<?php echo $module->id?>" data-jslide="<?php echo $i?>"><?php echo $i+1;?></li>
			<?php } ?>
		</ul>
	</div>
</div>
<?php if ($params->get('posttext') != ''){ ?>
<div class="text-block">
	<?php echo $params->get('posttext'); ?>
</div>
<?php } ?>


